#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef struct stu
{
	char name[20];
	int ch;
	int ma;
	int en;
	int sum;
}stu;
int main()
{
	int n = 0;
	scanf("%d", &n);
	stu* ps = (stu*)calloc(n, sizeof(stu));
	for (int i = 0; i < n; i++)
	{
		scanf("%s%d%d%d", ps[i].name, &ps[i].ch, &ps[i].ma, &ps[i].en);
		ps[i].sum = ps[i].ch + ps[i].ma + ps[i].en;
	}
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (abs(ps[i].ch - ps[j].ch) <= 5 && abs(ps[i].en - ps[j].en) <= 5 && abs(ps[i].ma - ps[j].ma) <= 5 && abs(ps[i].sum - ps[j].sum) <= 10)
			{
				printf("%s %s\n", ps[i].name, ps[j].name);
			}
		}
	}
	return 0;
}